///引入共享头部
import '../../common/shard.dart';
///引入仓库
import '../../store/main.dart';

final List list=[1,3,5];
class HomePage extends StatelessWidget {
	const HomePage({Key? key}) : super(key: key);

	changeTheme(){
		Get.bottomSheet(Container(
			color: Colors.white,
			child:ThemeChangeDialog()
		));
	}

	void generateError() async {
		throw "Test exception";
	}

	@override
	Widget build(BuildContext context) {
		return GetBuilder<MainStore>(builder: (store){
			return CustomCupertinoScaffold(
				titleText: "首页",
                navBackgroundColor: Theme.of(context).primaryColor,
				body: Column(
					mainAxisAlignment: MainAxisAlignment.center,
					crossAxisAlignment: CrossAxisAlignment.center,
					children:  [
						const Text("Hello Flutter"),
						TextButton(
							onPressed: (){
								Get.toNamed('/detail',arguments: "I'm xiaobaozi");
							},
							child: const Text("下一页")
						),
						TextButton(
							onPressed: getText,
							child: const Text("错误捕获")
						),
						TextButton(
							onPressed: changeTheme,
							child: const Text("切换主题")
						),
						TextButton(
							onPressed: (){
								Get.toNamed('/example');
							},
							child: const Text("一些插件演示")
						),
						TextButton(
							onPressed: (){
								Get.toNamed('/ui');
							},
							child: const Text("一些UI演示")
						),
					],
				),
			);
		});
	}

  	getText(){
		return list[list.length+1];
	}
}


class ThemeChangeDialog extends StatefulWidget {
    ThemeChangeDialog({Key? key}) : super(key: key);

    @override
    _ThemeChangeDialogState createState() => _ThemeChangeDialogState();
}

class _ThemeChangeDialogState extends State<ThemeChangeDialog> {

    MainStore mainStore = Get.put(MainStore());

    @override
    Widget build(BuildContext context) {
        return GetBuilder<MainStore>(builder: (store){
            return SizedBox(
                height: 300,
                child:GridView.count(
                    padding: EdgeInsets.all(15.w),
                    crossAxisCount: 4,
                    childAspectRatio: 1,
                    mainAxisSpacing: 15.w,
                    crossAxisSpacing: 15.w,
                    children: [
                        ...store.allTheme.map((item) => TapOpacity(
                            onTap: (){
                                store.changeTheme(item.key);
                            },
                            child: Container(
                                color: item.theme.primaryColor,
                                child: Center(
                                    child: store.currentTheme.primaryColor==item.theme.primaryColor?Icon(Icons.done,color: Colors.white):null,
                                ),
                            ))
                        ).toList()
                    ],
                ),
            );
        });

    }
}
